import java.util.*;
import java.io.*;
import java.net.*;
public class Server_Main
{
	public static void main(String args[])
	{
	Scanner scanner = new Scanner(System.in);
	ServerSocket server = null;
	ServerThread thread;
	Socket kehu = null;
	while (true){
	try {
	server = new ServerSocket(2010);
	}
	catch(IOException e1){
		System.out.println("正在监听");
	}
	try {
		System.out.println("等待客户呼叫");

		kehu = server.accept();
		System.out.println("客户地址："+kehu.getInetAddress());

	}
	catch (Exception e)
	{
		System.out.println("正在等待客户"+e);
	}
	if (kehu !=null){
	new ServerThread(kehu).start(); } //为每个客户启动一个专门的线程
   }
  }
}
class ServerThread extends Thread{
	Scanner scanner = new Scanner(System.in);
	Socket socket;
	DataOutputStream out=null;
	DataInputStream in=null;
	String s = null;
	ServerThread(Socket t)
	{
		socket = t;
		try
		{
			out = new DataOutputStream(socket.getOutputStream());
			in = new DataInputStream(socket.getInputStream());
			for(int i=0;i<10;i++)
		{
			String s=in.readUTF();   //in读取信息，阻塞状态
			System.out.println("服务器收到客户提问："+s);
			out.writeUTF(scanner.nextLine());
		
		}
		}
		catch (IOException e){}
	}
	
}